﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace TuongLai_Schools
{
    public class cls_DM_Hanhkiem
    {
        public DataTable GetAll_Hanhkiem(int caphocid)
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select HanhKiemID,GioiHangDuoi,GioiHangTren,TenHanhKiem,GhiChu,isChangeable from DM_HanhKiem where FK_CapHocID="+ caphocid +"");
            return dataTable;
        }
        public DataTable GetAll_Caphoc()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select ROW_NUMBER() OVER(ORDER BY TenCapHoc) as TT, CapHocID,TenCapHoc from DM_CapHoc");
            return dataTable;
        }
        public bool Insert(clsDM_Hanhkiem obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HanhKiemID", obj.HanhKiemID);
                db.AddParameter("@TenHanhKiem", obj.TenHanhKiem);
                db.AddParameter("@GioiHangDuoi", obj.GioiHangDuoi);
                db.AddParameter("@GioiHangTren", obj.GioiHangTren);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.ExecuteNonQuery("insert into DM_HanhKiem(TenHanhKiem,GioiHangDuoi,GioiHangTren,GhiChu,isChangeable,FK_CapHocID) values(N'" + obj.TenHanhKiem + "',"+ obj.GioiHangDuoi +","+ obj.GioiHangTren +",N'" + obj.GhiChu + "','" + obj.isChangeable + "',"+ obj.FK_CapHocID +")");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Hanhkiem obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HanhKiemID", obj.HanhKiemID);
                db.AddParameter("@TenHanhKiem", obj.TenHanhKiem);
                db.AddParameter("@GioiHangDuoi", obj.GioiHangDuoi);
                db.AddParameter("@GioiHangTren", obj.GioiHangTren);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.ExecuteNonQuery("update DM_HanhKiem set TenHanhKiem=N'" + obj.TenHanhKiem + "',GioiHangDuoi="+ obj.GioiHangDuoi +",GioiHangTren="+ obj.GioiHangTren +",GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "',FK_CapHocID="+ obj.FK_CapHocID +" where HanhKiemID='" + obj.HanhKiemID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Hanhkiemid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HanhKiemID", Hanhkiemid);
                db.ExecuteNonQuery("delete DM_HanhKiem where HanhKiemID='" + Hanhkiemid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
